#include "CIconElement.h"

CIconElement::CIconElement( const QString& iPrefixPath, 
	const QString& iconPath, const int& index,const QString& cmdKey)
	:LeafElement(iconPath, index,cmdKey),_iPrefixPath(iPrefixPath)
{

}



void CIconElement::drawElement(QWidget* widget, QPainter* painter, bool bSelected, const QRect& rect)
{
	setRect(rect);
	LeafElement::drawElement(widget, painter, bSelected, rect);
	drawIcon(painter, bSelected);
}

void CIconElement::drawIcon(QPainter* painter, bool bSelected)
{
	QRect imageRect;
	
	QString iconPath = _iPrefixPath + (bSelected ? QString("/s/%1s.png").arg(_index) : QString("/n/%1n.png").arg(_index));
	QPixmap pixmap(iconPath);
	if (pixmap.isNull()) {
		return;
	}
	imageRect = QRect(_rect.topLeft(), pixmap.size());
	painter->drawPixmap(imageRect, pixmap);
	if (_otherInfo.toInt() == _index) {
		QPixmap pixmap(":/UI/icon/common/select.png");
		if (pixmap.isNull()) {
			return;
		}
		painter->drawPixmap(QRect(imageRect.topRight() + QPoint(16, 2), pixmap.size()), pixmap);
	}
}


